﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace AirplaneReservation
{
    public partial class TicketStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void view_Click(object sender, EventArgs e)
        {
            SqlConnection ccon = new SqlConnection(ConfigurationManager.ConnectionStrings["airplaneConnectionString"].ToString());
            ccon.Open();
            string sql ="SELECT [FirstName], [LastName], [FlightCode], [originCity], [desCity], [DepartureTime] as Departure, [Name] as Class, [FinalPrice] as Price, [Code] FROM [View_TicketStatus] where Code='"+ticketNo.Text+"'";
            SqlDataAdapter da = new SqlDataAdapter(sql, ccon);
            DataTable dt = new DataTable();
            da.Fill(dt);

            int count = dt.Rows.Count;
            if (count != 0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
                GridView1.Visible = true;
                Label1.Text = "";
            }
            else
            {
                Label1.Text = "Wrong code. Please enter again";
                GridView1.Visible = false;
            }

        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[8].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[8].Visible = false;
            }
        }
    }
}